package com.example.boosttestandroid.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.boosttestandroid.R;
import com.example.boosttestandroid.interfac.OnClickTabListener;
import com.example.boosttestandroid.widget.CommonTitleBar;
import com.idlefish.flutterboost.FlutterBoost;
import com.idlefish.flutterboost.FlutterBoostRouteOptions;

import java.util.HashMap;
import java.util.Map;

public class UserFragment extends Fragment implements OnClickTabListener {

    private CommonTitleBar titlebar;
    private TextView btnTV;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View userView = inflater.inflate(R.layout.activity_me, container, false);
        initWithUserFragment(userView);
        return userView;
    }

    /**
     * Fragment 初始化
     */
    private void initWithUserFragment(final View hpView) {
        btnTV = hpView.findViewById(R.id.tv_flutter);
        titlebar = hpView.findViewById(R.id.title_view);
        titlebar.setTitleView("我的页面 - 这是原生页面");
        titlebar.hideLeftView();

        btnTV.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                System.out.println("跳转到Flutter");
                gotoFlutter();
            }
        });
    }

    /**
     * 跳转到 Flutter 页面
     */
    private void gotoFlutter() {
        Map<String, Object> params = new HashMap();
        FlutterBoostRouteOptions options = new FlutterBoostRouteOptions.Builder()
                .pageName("simplePage")
                .arguments(params)
                .build();
        FlutterBoost.instance().open(options);
    }

    @Override
    public void onclick(int position) {

    }
}
